<template>
  <div style="width: 100%; height: 100%;">
    <div class="treeHeader">
      <Tabs v-model="tabsVal">
        <TabPane :label="$t('m.dàifēnpèi')" name="name1">
          <WaitAllocation :tabsVal="tabsVal"/>
        </TabPane>
        <TabPane :label="$t('m.yǐfēnpèikěhuíshōu')" name="name2">
          <AlreadyAllocation :tabsVal="tabsVal"/>
        </TabPane>
      </Tabs>
    </div>
    <!-- 分配初级人员 -->
    <Modal
      v-model="adminAllotButton"
      :title="$t('m.fēnpèichūjírényuán')"
      @on-ok="adminAllotButtonOk"
      @on-cancel="adminAllotButtonCancel"
    >
      <h4 style="display: inline; margin: 35px;">{{$t('m.qǐngxuǎnzé')}}</h4>
      <Select
        v-model="adminAllotSelectData"
        style="width:60%; margin:auto;"
        v-bind:placeholder="$t('m.chushen')"
      >
        <Option
          v-for="item in adminFirstInstanceDataList"
          :value="item.account"
          :key="item.account"
        >{{ item.account }}</Option>
      </Select>
    </Modal>
  </div>
</template>

<script>
import AlreadyAllocation from "./alreadyAllocation";
import WaitAllocation from "./waitAllocation";

export default {
  components: {
    WaitAllocation,
    AlreadyAllocation
  },
  data() {
    return {
      tabsVal: "",
      adminAllotButton: false,
      adminFirstInstanceDataList: [],
      adminAllotSelectData: ""
    };
  },
  mounted() {
    this.chuShenQueryPerson();
    this.tabsVal = "name1";
  },
  methods: {
    // 获取初审人员列表
    chuShenQueryPerson() {
      var url = `/api/laocai/sys/account/list?roleName=checker&enable=1`;
      this.$http.get(url).then(res => {
        if (res.data.code == 0) {
          this.adminFirstInstanceDataList = res.data.result.list;
        } else {
          this.$Message.success(this.$t("m.errorCode" + res.body.code));
        }
      });
    },
    // 分配初审人员确定
    adminAllotButtonOk() {
      this.$axios({
        method: "post",
        url: "/api/laocai/check/first/assign",
        headers: {
          "x-peacock-auth": localStorage.getItem("x-peacock-auth"),
          "Content-Type": "application/json;charset=UTF-8"
        },
        params: {},
        data: {
          orderGids: this.chuShenSelectData,
          operator: this.adminAllotSelectData
        }
      })
        .then(res => {
          if (res.data.code == 0) {
            this.chuShenQuery(1);
            this.adminAllotSelectData = "";
          } else {
            this.$Message.success(this.$t("m.errorCode" + res.body.code));
          }
        })
        .catch(error => {
          this.$Message.warning(this.$t("m.qǐngqiúcuòwù"));
          console.log(error);
        });
    },
    // 分配初审人员取消
    adminAllotButtonCancel() {
      this.adminAllotSelectData = "";
    }
  }
};
</script>

<style lang="scss" scoped>
.treeHeader {
  margin: 0 20px;
  padding-top: 20px;
}
</style>
